<?php
/**
 * web feed helper : rss and atom
 *
 * @author tom.wang<tom.wang.sz@qq.com>
 */
class Feed {
	protected $cfg;
	
	public function __construct($cfg = array()) {
		$this->setCfg($cfg);
	}
	
	/**
	 * return the source string
	 *
	 * @return string
	 */
	public function html() {
		$clzName = ucfirst(strtolower($this->cfg['type'])) . 'FeedStyle';
		$clzFile = FRAMEWORK_FEED_ROOT . "drivers/{$clzName}.class.php";
		if(file_exists($clzFile)) require_once $clzFile;
		$style = new $clzName($this->cfg['data']);
		
		return $style->html();
	}
	
	/**
	 * echo directly
	 *
	 */
	public function render() {
		echo $this->html();
	}
	
	/**
	 * set config
	 *
	 * @param array $cfg
	 */
	protected function setCfg($cfg) {
		$this->cfg = require FRAMEWORK_FEED_ROOT . 'config.php';
		
		foreach($cfg as $key => $val) {
			if(array_key_exists($key, $this->cfg)) $this->cfg[$key] = $val;
		}
	}
}
?>